#ifndef BLE_DISCOVERY_H
#define BLE_DISCOVERY_H

#include <qbluetoothaddress.h>
#include <qbluetoothdevicediscoveryagent.h>
#include <qbluetoothlocaldevice.h>
#include <qbluetoothdeviceinfo.h>
#include <qbluetoothservicediscoveryagent.h>
#include <QBluetoothServiceDiscoveryAgent>
#include <QBluetoothDeviceDiscoveryAgent>
#include <QLowEnergyController>
#include <QBluetoothServiceInfo>

#include <QDebug>
#include <QList>
#include <QTimer>
#include <QObject>
#include <QTimer>


QT_FORWARD_DECLARE_CLASS (QBluetoothDeviceInfo)
QT_FORWARD_DECLARE_CLASS (QBluetoothServiceInfo)


class ble_discovery : public QObject
{
    Q_OBJECT
    Q_PROPERTY(bool state READ state NOTIFY stateChanged)
    Q_PROPERTY(int curSelect READ curSelect WRITE setCurSelect NOTIFY curSelectChanged)
public:
    ble_discovery(QString devName);

    ~ble_discovery();

    bool state() const {
        return m_state;
    }
    int curSelect() const {
        return m_curSelect;
    }

public slots:
    void setValue(int val);
    void setCurSelect(int val) {
        setValue(val);
    }

signals:
    void appendInfo(QString str);

private slots:
    void devDiscovered(QBluetoothDeviceInfo info);

    void deviceScanError(QBluetoothDeviceDiscoveryAgent::Error error);
    void deviceConnected();
    void errorReceived(QLowEnergyController::Error);
    void deviceDisconnected();
    void lowEnergyService(const QBluetoothUuid &serviceUuid);
    void serviceDetailsDiscovered(QLowEnergyService::ServiceState newState);

    void demons();

    void characteristicRead(const QLowEnergyCharacteristic &characteristic, const QByteArray &value);
Q_SIGNALS:
    void stateChanged();
    void curSelectChanged();

private:
    QString deviceName;
    QString deviceMac;
    QLowEnergyService *m_service;
    QLowEnergyCharacteristic m_character;
    QBluetoothDeviceDiscoveryAgent *discoveryAgent;
    QLowEnergyController *controller;
    QTimer *pTimer;
    bool m_state;
    int m_curSelect;
};

#endif // BLE_DISCOVERY_H
